package learningThread.syn.synchronizedMethodLockObj.communicate.pipeStream;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

/**
 * 用于多线程之间进行通讯，
 */
public class TestPipeStream {

    public static void main(String[] args) {
        try {
            WriteData writeData = new WriteData();
            ReadData readData = new ReadData();

            PipedInputStream pipedInputStream = new PipedInputStream();
            PipedOutputStream pipedOutputStream = new PipedOutputStream();

            //连接
            pipedOutputStream.connect(pipedInputStream);

            ThreadRead reanThread = new ThreadRead(readData, pipedInputStream);
            reanThread.start();

            ThreadWrite threadWrite = new ThreadWrite(writeData, pipedOutputStream);
            threadWrite.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
